# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import logging

from odoo import api, fields, models, _
from odoo.exceptions import AccessDenied, UserError

_logger = logging.getLogger(__name__)

class CrStation(models.Model):
    _name = "cr.station"
    _description = "CrStation"

    code = fields.Char()
    name = fields.Char()

class CrSchedule(models.Model):
    _name = "cr.schedule"
    _description = "CrSchedule"

    active = fields.Boolean(default=True, help="Set active to false to hide the schedule without removing it.")
    train_code = fields.Char()
    direction = fields.Selection([
        ('up', '上行'),
        ('down', '下行'),
        ('none', '未知')], default='none')

    first_station_id = fields.Many2one('cr.station')
    dest_station_id = fields.Many2one('cr.station')

    first_time = fields.Datetime()
    dest_time = fields.Datetime()
    station_ids = fields.One2many('cr.schedule.station', 'schedule_id')


class CrScheduleStation(models.Model):
    _name = "cr.schedule.station"
    _description = "CrScheduleStation"

    schedule_id = fields.Many2one('cr.schedule')
    sequence = fields.Integer()

    station_id = fields.Many2one('cr.station')
    last_station_id = fields.Many2one('cr.station')
    next_station_id = fields.Many2one('cr.station')

    arrive_time = fields.Datetime()
    leave_time = fields.Datetime()


